<?php
namespace BoxSns\Behaviors;
class IntBehavior extends \Think\Behavior
{
    //教育网站初始化
    public function run(&$param)
    {
        ignore_user_abort(true);
        set_time_limit(0);
        /********教育网站会员初始化***/
        $this->edu_user();
        /*******自动取消订单程序**/
        $this->CancelOrder();


    }

    /*******教育网站的会员****/
    public function edu_user()
    {
        $user_id = session("user_id");
        $data = BoxModel("edu_user")->where("user_id='$user_id'")->find();
        if (!$data) {
            BoxModel("edu_user")->add(array('user_id' => $user_id));
        }
    }

    /******自动取得订单***/
    public function CancelOrder()
    {
        $order_vailtime = dict("setting");
        $order_vailtime = intval($order_vailtime['autoCancelOrder']);
        $date = date("Y-m-d H:i:s", strtotime("-$order_vailtime hour"));
        $model = BoxModel("EduSubjectOrder");
        $data = $model->where("addtime<'$date' and status=1")->select();
        foreach ($data as $one) {
            $order_sn = $one['order_sn'];
            $model->cancel($order_sn);
        }
    }


}
